#include<bits/stdc++.h>
#define int long long 

using namespace std;

signed main() {
	int n;
	cin >> n;
	int a[n + 10];
	
	for(int i = 1; i <= n; i ++ ) {
		cin >> a[i];
	}
	
	int t = 0, ret = 0;
	for(int i = 3; i <= n; i ++ ) {
		if(a[i] - a[i - 1] == a[i - 1] - a[i - 2]) {
			t ++;
		} else {
			ret += (t + 1) * (t) / 2;
			t = 0;
			//cout << "i = " << i << " ret = " << ret << endl;
		}
	}
	ret += (t + 1) * (t) / 2;
	
	ret += n;
	ret += (n - 1);
	
	cout << ret << endl;
	return 0;
}

